//
//  SquareMarkView.m
//  安好
//
//  Created by rlp on 14-11-14.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "SquareMarkView.h"

@implementation SquareMarkView
-(id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backGroundColorArray = [[NSArray alloc]initWithObjects:[ClassMethodsViewController colorWithHexString:@"#a99dff"],[ClassMethodsViewController colorWithHexString:@"#4fc1e9"],[ClassMethodsViewController colorWithHexString:@"#ff9d9d"],[ClassMethodsViewController colorWithHexString:@"#ffbb5b"],[ClassMethodsViewController colorWithHexString:@"#60dec5"],[ClassMethodsViewController colorWithHexString:@"#717171"], nil];
        self.textArray = [[NSArray alloc]initWithObjects:
                          @"全",
                          @"精",
                          @"顶",
                          @"新",
                          @"图",
                          @"无",nil];
        
        
//    [self loadMarkView];
    }
    return self;
}
-(void)loadMarkView{
    if (self.squareMarkStyles.count==0||[self.squareMarkStyles isEqual:[NSNull null]]||self.squareMarkStyles==nil) {
        self.frame= CGRectZero;
        return;
    }
    for (int i=0; i<self.squareMarkStyles.count; i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((SQUARE_MARK_SIDE+SQUARE_MARK_INTERVAL)*i, 0, SQUARE_MARK_SIDE, SQUARE_MARK_SIDE)];
        
        switch ([[self.squareMarkStyles objectAtIndex:i] integerValue]) {
            case SquareMarkStyleAll:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStyleAll];
                label.text = [self.textArray objectAtIndex:SquareMarkStyleAll];
            }
                break;
            case SquareMarkStyleRefinement:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStyleRefinement];
                label.text = [self.textArray objectAtIndex:SquareMarkStyleRefinement];
            }
                break;
            case SquareMarkStylePeak:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStylePeak];
                label.text = [self.textArray objectAtIndex:SquareMarkStylePeak];
            }
                break;
            case SquareMarkStyleNew:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStyleNew];
                label.text = [self.textArray objectAtIndex:SquareMarkStyleNew];
            }
                break;
            case SquareMarkStyleAdsum:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStyleAdsum];
                label.text = [self.textArray objectAtIndex:SquareMarkStyleAdsum];
            }
                break;
            case SquareMarkStyleNot:
            {
                label.backgroundColor = [self.backGroundColorArray objectAtIndex:SquareMarkStyleNot];
                label.text = [self.textArray objectAtIndex:SquareMarkStyleNot];
            }
                break;
             default:
                break;
        }
 
        label.textColor = [UIColor whiteColor];

        label.font = [UIFont systemFontOfSize:SQUARE_MARK_FONT];
        label.textAlignment = NSTextAlignmentCenter;
        label.layer.cornerRadius = CORNERRADIUS;
        label.layer.masksToBounds = YES;
        
        
        [self addSubview:label];
    }
    
    float markViewWith = SQUARE_MARK_SIDE*self.squareMarkStyles.count+SQUARE_MARK_INTERVAL*(self.squareMarkStyles.count-1);
    
    self.frame = CGRectMake(kScreenWidth-markViewWith-15, self.frame.origin.y, markViewWith, SQUARE_MARK_SIDE);
}

-(void)setSquareMarkStyles:(NSArray *)squareMarkStyles{
    _squareMarkStyles = squareMarkStyles;
    [self loadMarkView];
}


@end
